import OperateLog from "@/views/main/OperateLog.vue";
import axios from "../utils/request";
import base from "./base";

const api = {
    /**
     * 注册
     */
    register(params){
        return axios.post(base.baseUrl + base.register,params,{
            headers: {
              'Content-Type': 'application/json'
            }
          })
    },
    /**
     * 忘记密码
     */
      forget(params){
          return axios.post(base.baseUrl + base.forget,params,{
              headers: {
                'Content-Type': 'application/json'
              }
            })
      },
    /**
     * 登录
     */
    login(params){
        return axios.post(base.baseUrl + base.login,params,{
            headers: {
              'Content-Type': 'application/json'
            }
          })
    },
    logout(){
      return axios.get(base.baseUrl + base.logout)
    },
     /**
     * 发送验证码
     */
    getRandom(params){
        const formData = new FormData();
        formData.append('email', params.email);
        return axios.post(base.baseUrl + base.getRandom,formData)
    },
     /**
     * 更改用户信息
     */
    updateUserInfo(params){
      return axios.post(base.baseUrl + base.updateUserInfo,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    /**
     * 查询所有用户
     */
    getUserByPosition(isAll,isPage,params){
      const formData = new FormData();
      formData.append('isAll', isAll);
      formData.append('isPage', isPage);
      if(params.username){
        formData.append('username', params.username);
      }
      if(params.pageNow){
        formData.append('pageNow', params.pageNow);
      }
      return axios.post(base.baseUrl + base.getUserByPosition,formData)
    },

    userDelete(params){
      const formData = new FormData();
      formData.append('userIds', params);
      return axios.post(base.baseUrl + base.userDelete,formData)
    },

    saveOrUpdateByUserId(params){
      return axios.post(base.baseUrl + base.saveOrUpdateByUserId,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },

    /**
     * 楼宇相关接口
     */
    /**
     * 获取楼宇信息
     */
    buildList(params){
      return axios.post(base.baseUrl + base.buildList,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    buildListAll(){
      return axios.post(base.baseUrl + base.buildListAll)
    },

    /**
     * 通过ID删除楼宇信息
     */
    buildDelete(params){
      const formData = new FormData();
      formData.append('buildId', params);
      return axios.post(base.baseUrl + base.buildDelete,formData)
    },

    /**
     * 新增楼宇信息
     */
    saveOrUpdateBuild(params){
      return axios.post(base.baseUrl + base.saveOrUpdateBuild,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },

    /**
     * 房屋相关接口
     */
    /**
     * 获取房屋信息
     */
    hostelList(params){
      return axios.post(base.baseUrl + base.hostelList,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },

    /**
     * 通过ID删除房屋信息
     */
    hostelDelete(params){
      const formData = new FormData();
      formData.append('hostelIds', params);
      return axios.post(base.baseUrl + base.hostelDelete,formData)
    },

    /**
     * 新增房屋信息
     */
    saveOrUpdateHostel(params){
      return axios.post(base.baseUrl + base.saveOrUpdatehostel,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },    

    /**
     * 文件相关接口
     */
    /**
     * 上传文件
     */
    uploadFile(params){
      const formData = new FormData();
      formData.append('file', params); // file 是文件对象
  
      return axios.post(base.baseUrl + base.ossFileUpload, formData, {
        headers: {
          'Content-Type': 'multipart/form-data', // 设置请求头
        },
      });
    },

    /**
     * 操作日志相关接口
     */
    /**
     * 获取操作日志列表
     */
    operateLogList(params){
      return axios.post(base.baseUrl + base.operateLogList,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    /**
     * 获取近七天数据
     */
    getRecord(){
      return axios.post(base.baseUrl + base.recordList)
    },

    /**
     * 公告相关接口
     */
    /**
     * 添加公告
     */
    noticeAdd(params){
      return axios.post(base.baseUrl + base.noticeAdd,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    /**
     * 查询公告
     */
    noticeList(params){
      return axios.post(base.baseUrl + base.noticeList,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    /**
     * 通过ID删除公告信息
     */
    noticeDelete(params){
          const formData = new FormData();
          formData.append('noticeInfoIds', params);
          return axios.post(base.baseUrl + base.noticeDelete,formData)
    },


    /**
     * 车位相关接口
     */
    /**
     * 获取车位信息
     */
    parkList(params){
      return axios.post(base.baseUrl + base.parkList,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    getPark(){
      return axios.post(base.baseUrl + base.getPark)
    },

    /**
     * 通过ID删除车位信息
     */
    parkDelete(params){
      const formData = new FormData();
      formData.append('parkIds', params);
      return axios.post(base.baseUrl + base.parkDelete,formData)
    },

    /**
     * 新增车位信息
     */
    saveOrUpdatePark(params){
      return axios.post(base.baseUrl + base.saveOrUpdatePark,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },

    /**
     * 维修上报相关接口
     */
    /**
     * 新增维修信息
     */
    saveOrUpdateUpkeep(params){
      return axios.post(base.baseUrl + base.saveOrUpdateUpkeep,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    getUpkeepNumber(){
      return axios.post(base.baseUrl + base.getUpkeepNumber)
    },
    upkeepList(params){
      return axios.post(base.baseUrl + base.upkeepList  ,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    deleteUpkeep(params){
      const formData = new FormData();
      formData.append('upkeepIds', params);
      return axios.post(base.baseUrl + base.deleteUpkeep,formData)
    },
    /**
     * 支付相关接口
     */
    /**
     * 付款
     */
    apiPay(id,price,urge){
      return axios.get(base.baseUrl + base.apiPay,{
        params: { orderNo: id, price: price,urge: urge }
      });
    },

    /**
     * 缴费管理相关接口
     */
    costList(params){
      return axios.post(base.baseUrl + base.costList  ,params,{
        headers: {
          'Content-Type': 'application/json'
        }
      })
    },
    getCostInfo(){
      return axios.post(base.baseUrl + base.getCostInfo)
    },
    getCostInfoByMonth(){
      return axios.post(base.baseUrl + base.getCostInfoByMonth)
    },
    /**
     * 删除缴费
     */
    deleteCost(params){
      const formData = new FormData();
      formData.append('costIds', params);
      return axios.post(base.baseUrl + base.deleteCost,formData)
    },
    /**
     * 催缴
     */
    urgeCost(params){
      const formData = new FormData();
      formData.append('userId', params.userId);
      formData.append('costId', params.id);
      return axios.post(base.baseUrl + base.urgeCost,formData)
    }
}

export default api;